package com.dony.web.controller.shop;

import com.dony.common.core.controller.BaseController;
import com.dony.common.core.domain.AjaxResult;
import com.dony.common.core.page.TableDataInfo;
import com.dony.shop.domain.ShopeeMerchant;
import com.dony.shop.domain.ShopeeShop;
import com.dony.shop.domain.vo.RegionVo;
import com.dony.shop.service.IShopeeShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 授权店铺Controller
 *
 * @author Dominic
 * @date 2022-08-23
 */
@RestController
@RequestMapping("/shopee/shop")
public class ShopeeShopController extends BaseController
{
    @Autowired
    private IShopeeShopService shopService;

    /**
     * 查询授权店铺列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ShopeeShop shop)
    {
        startPage();
        List<ShopeeShop> shops = shopService.listByParam(shop);
        TableDataInfo dataTable = getDataTable(shops);
        //封装shop数据
        List<ShopeeMerchant> vos = shopService.handleShopList(shops);
        dataTable.setRows(vos);
        return dataTable;
    }


    /**
     * 获取本土店铺下拉列表
     *
     * @return
     */
    @RequestMapping("/merchant")
    public AjaxResult getShopList(@RequestParam(required = false) Long merchantId) {
        return AjaxResult.success(shopService.getShoplist(merchantId));
    }

    /**
     * 获取授权店铺详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(shopService.getById(id));
    }

    /**
     * 修改授权店铺
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ShopeeShop shop)
    {
        return toAjax(shopService.updateById(shop));
    }

}
